
def get_hex_code(input_file, output_file):
    hex_code = []
    with open(input_file, "rb") as fp:
        code_bin = fp.read(1)
        print(type(code_bin))
        while code_bin:
            code_hex = '0x' + code_bin.hex().zfill(2)
            hex_code.append(code_hex)
            code_bin = fp.read(1)
    with open(output_file, "w") as ff:
         i = 0
         ff.write('uchar initcode[] = {')
         for code in hex_code:
             if i % 8 == 0:
                 ff.write('\n\t')
             ff.write(code + ', ')
             i = i + 1
         ff.write('\n};')

get_hex_code("./user/initcode", "./user/initcode.hex")
